﻿
namespace verginia
{
    /// <summary>
    /// 加密类
    /// </summary>
    public class MyEncodes
    {
        /// <summary>
        /// 明文类
        /// </summary>
        public string PlainText { get; set; }

        /// <summary>
        /// 密文类
        /// </summary>
        public string CipherText { get; set; }

        /// <summary>
        /// 密钥类
        /// </summary>
        public string Key { get; set; }

        /// <summary>
        /// 加密类
        /// </summary>
        public void Encode()
        {
            //todo 加密过程
            for(int i=0,j=0;i<PlainText.Length;i++,j++)
            {
                //根据密钥长度将明文分组与密钥对应
                if(j % Key.Length == 0) 
                    j= 0;
                int number = (CharToInt(PlainText[i]) + CharToInt(Key[j]))%26;
                CipherText +=Convert.ToChar(number+'a');
            }
        }

        /// <summary>
        /// 返回指定字符在字母表中的序号，从0开始
        /// </summary>
        /// <param name="ch"></param>
        /// <returns></returns>
        private int CharToInt(char ch)
        {
            return ch - 'a';
        }
    }
}
